1 module hip.assets.image; 2 3 //Reserved for future implementation. 4 import hip.asset; 5 import hip.image; 6 import hip.util.reflection; 7 8 9 /** 10 * This class represents pixel data on RAM (CPU Powered) 11 * this is useful for loading images on another thread and then 12 * sending it to the GPU 13 */ 14 public class Image : HipAsset, IImage 15 { 16 HipImageImpl impl; 17 string imagePath; 18 int width,height; 19 20 this(in string path) 21 { 22 super("Image_"~path); 23 _typeID = assetTypeID!Image; 24 initialize(path); 25 } 26 27 this(in string path, in ubyte[] buffer, void delegate(IImage self) onSuccess, void delegate() onFailure) 28 { 29 this(path); 30 loadFromMemory(cast(ubyte[])buffer, onSuccess, onFailure); 31 } 32 private void initialize(string path) 33 { 34 import hip.util.system : sanitizePath; 35 impl = new HipImageImpl(path); 36 imagePath = sanitizePath(path); 37 } 38 static alias getPixelImage = HipImageImpl.getPixelImage; 39 40 mixin(ForwardInterface!("impl", IImage)); 41 42 void loadRaw(in ubyte[] pixels, int width, int height, ubyte bytesPerPixel) 43 { 44 impl.loadRaw(pixels, width, height, bytesPerPixel); 45 this.width = width; 46 this.height = height; 47 } 48 bool loadFromMemory(ubyte[] data,void delegate(IImage self) onSuccess, void delegate() onFailure) 49 { 50 bool ret = this.impl.loadFromMemory(data, (IImage self) 51 { 52 this.width = impl.getWidth; 53 this.height = impl.getHeight; 54 onSuccess(this); 55 }, onFailure); 56 return ret; 57 } 58 59 60 override void onDispose(){impl.dispose();} 61 override void onFinishLoading(){} 62 alias w = width; 63 alias h = height; 64 }